package com.ruoyi.controller.middlesign.timing;

import com.alibaba.fastjson.JSON;
import com.ruoyi.controller.middlesign.MiddlesMethod;
import com.ruoyi.service.middlesign.MiddlesignService;
import com.ruoyi.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 定时B2801查询B2801授权  B2802明细发送
 * @date 2021/3/15 16:14
 */
@Component
public class Yi {

    @Autowired
    MiddlesignService middlesignService;

    public void yi() {
        //查询数据库中的核心企业集合
        List<Map<String, Object>> hxqyList = middlesignService.findHxqyList();
        for (Map map : hxqyList) {
            //获取核心企业的名称和统一社会代码
            String hxqyName = map.get("name").toString();
            String hxqyCode = map.get("code").toString();

            //这个List用来存储B2801返回的授权信息集合
            List<Map<String, Object>> maps = MiddlesMethod.getAuthorizationList(hxqyCode,hxqyName);

            if (maps.size() > 0) {
                for (Map map1 : maps) {
                    //取出授权码
                    String CREDIT_NO = map1.get("CREDIT_NO").toString();
                    //取出供应商名称
                    String CREDIT_NAME = map1.get("CREDIT_NAME").toString();
                    //取出供应商社会信用代码
                    String CREDIT_CODE = map1.get("CREDIT_CODE").toString();
                    //设置sql所需参数
                    Map map2 = new HashMap();
                    map2.put("CREDITNAME", CREDIT_NAME);
                    map2.put("hxqyName", hxqyName);
                    map2.put("table", "ZZ_YFZK_JS");
                    //查询出推送数据
                    List<Map<String, Object>> maps1 = middlesignService.findHistoryData(map2);
                    //转换成jsonString
                    String jsonString = JSON.toJSONString(maps1);
                    //生成文件并推送
                    BaseResult baseResult = middlesignService.pushHistoryData(jsonString, CREDIT_CODE, CREDIT_NO, CREDIT_NAME, hxqyName, hxqyCode, "ZZ_YFZK_JS");
                    System.out.println(baseResult);
                }
            }
        }
    }

}
